/*
 * ============================================================================
 *
 *       Filename:  echo.c
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2014年04月17日 10时28分19秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  jianxi sun (jianxi), ycsunjane@gmail.com
 *   Organization:  
 *
 * ============================================================================
 */
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

#include <lua.h>  
#include <lualib.h>  
#include <lauxlib.h> 


static void *l_alloc (void *ud, void *ptr, size_t osize,
	size_t nsize) {
	(void)ud;  (void)osize;  /*  not used */
	if (nsize == 0) {
		free(ptr);
		return NULL;
	}
	else
		return realloc(ptr, nsize);
}

int main()
{
	lua_State * luaenv = lua_newstate(l_alloc, NULL);
	if(luaenv == NULL) {
		printf("create lua_newstate failed\n");
		return -1;
	}

	luaL_openlibs(luaenv);
	
	luaL_loadfile(luaenv, "echo.lua");
	lua_pcall(luaenv, 0, 0, 0);
	lua_close(luaenv);
}
